home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / GMS / GMSDev / Source / Asm / System / RamboWormNasty.s < prev    next >
Encoding:
Text File  |  1998-04-16  |  6.1 KB  |  272 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;This is the same as the RamboWorm demo but it doesn't free any of its
  3. ;resources!  This would normally crash our machine but the system can
  4. ;recover from such an instance and give back everything that was allocated.
  5. ;
  6. ;If you need proof that the resource tracking works, take a memory count
  7. ;before you run the program and then compare the values to the memory
  8. ;after running the demo.
  9.  
  10.  
  11.     INCDIR    "GMSDev:Includes/"
  12.     INCLUDE    "dpkernel/dpkernel.i"
  13.  
  14.     SECTION    "Demo",CODE
  15.  
  16. ;===========================================================================;
  17. ;                             INITIALISE DEMO
  18. ;===========================================================================;
  19.  
  20.     STARTDPK
  21.  
  22. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  23.     move.l    DPKBase(pc),a6
  24.     lea    BackgroundFile(pc),a0
  25.     moveq    #ID_PICTURE,d0
  26.     CALL    Load
  27.     move.l    d0,PIC_Background
  28.     beq    .Exit
  29.  
  30.     moveq    #ID_SCREEN,d0
  31.     CALL    Get
  32.     move.l    d0,Screen
  33.     beq    .Exit
  34.  
  35.     ;Copy picture details to screen.
  36.  
  37.     move.l    PIC_Background(pc),a0
  38.     move.l    PIC_Bitmap(a0),a2
  39.     move.l    Screen(pc),a1
  40.     move.l    #SCR_DBLBUFFER,GS_Attrib(a1)
  41.     CALL    CopyStructure
  42.  
  43. ;---------------------------------------------------------------------------;
  44. ;Initialise the screen.
  45.  
  46.     move.l    Screen(pc),a0    ;Initialise the screen.
  47.     sub.l    a1,a1
  48.     CALL    Init
  49.     tst.l    d0
  50.     beq.s    .Exit
  51.  
  52.     move.l    PIC_Background(pc),a0
  53.     move.l    PIC_Bitmap(a0),a0
  54.     move.l    Screen(pc),a1
  55.     move.l    GS_Bitmap(a1),a1
  56.     CALL    Copy
  57.  
  58.     move.l    BLTBase(pc),a6
  59.     move.l    Screen(pc),a0
  60.     moveq    #BUFFER2,d0
  61.     moveq    #BUFFER1,d1
  62.     CALL    bltCopyBuffer
  63.  
  64. ;---------------------------------------------------------------------------;
  65. ;Initialise the restore object.
  66.  
  67.     move.l    DPKBase(pc),a6
  68.     lea    RestoreTags(pc),a0
  69.     move.l    Screen(pc),a1    ;a1 = Screen.
  70.     CALL    Init    ;>> = Initialise the restore list.
  71.     tst.l    d0    ;d0 = Check for errors.
  72.     beq.s    .Exit    ;>> = Error, exit.
  73.  
  74. ;---------------------------------------------------------------------------;
  75. ;Load the bob file in.  This contains the graphics data that we are
  76. ;going to draw to the screen.
  77.  
  78.     lea    BBT_Rambo(pc),a0    ;a0 = Object.
  79.     move.l    Screen(pc),a1    ;a1 = Container.
  80.     CALL    Init    ;>> = Initialise bob to screen.
  81.     tst.l    d0
  82.     beq.s    .Exit
  83.  
  84.     lea    SMT_Rambo(pc),a0
  85.     sub.l    a1,a1
  86.     CALL    Init
  87.     tst.l    d0
  88.     beq.s    .Exit
  89.  
  90.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  91.     CALL    Get
  92.     move.l    d0,JoyData
  93.     beq.s    .Exit
  94.     move.l    d0,a0    ;Initialise the joydata structure.
  95.     sub.l    a1,a1
  96.     CALL    Init
  97.     tst.l    d0
  98.     beq.s    .Exit
  99.  
  100.     move.l    Screen(pc),a0
  101.     CALL    Display
  102.  
  103.     bsr.s    Main
  104.  
  105. .Exit
  106. ;    move.l    DPKBase(pc),a6
  107. ;    move.l    JoyData(pc),a0    ;Everything that should be freed
  108. ;    CALL    Free    ;has been commented out.  We won't
  109. ;    move.l    SND_Rambo(pc),a0    ;crash though, thanks to resource
  110. ;    CALL    Free    ;tracking.
  111. ;    move.l    BOB_Rambo(pc),a0
  112. ;    CALL    Free
  113. ;    move.l    Restore(pc),a0
  114. ;    CALL    Free
  115. ;    move.l    PIC_Background(pc),a0
  116. ;    CALL    Free
  117. ;    move.l    Screen(pc),a0
  118. ;    CALL    Free
  119.     MOVEM.L    (SP)+,A0-A6/D1-D7
  120.     moveq    #ERR_OK,d0
  121.     rts
  122.  
  123. ;===========================================================================;
  124. ;                                MAIN LOOP
  125. ;===========================================================================;
  126.  
  127. SPEED    =    5
  128. FIRESPEED =    0
  129.  
  130. Main:    moveq    #$00,d7
  131.  
  132. .Loop    move.l    DPKBase(pc),a6
  133.     move.l    Restore(pc),a0    ;a0 = Restore list.
  134.     CALL    Activate    ;>> = Restore the backgrounds.
  135.  
  136.     move.l    BOB_Rambo(pc),a0
  137.     CALL    Draw    ;>> = Blit the bob.
  138.  
  139.     move.l    SCRBase(pc),a6
  140.     CALL    scrWaitAVBL    ;>> = Wait for VBL.
  141.  
  142.     move.l    Screen(pc),a0
  143.     CALL    scrSwapBuffers
  144.  
  145.     addq.w    #1,d7
  146.  
  147.     move.l    DPKBase(pc),a6
  148.     move.l    BOB_Rambo(pc),a1
  149.     tst.b    FireState
  150.     bne.s    .FireOn
  151.  
  152.     cmp.w    #SPEED,d7
  153.     ble.s    .Move
  154.     moveq    #$00,d7
  155.     addq.w    #1,BOB_Frame(a1)
  156.     cmp.w    #9,BOB_Frame(a1)
  157.     blt.s    .Move
  158.     clr.w    BOB_Frame(a1)
  159.     bra.s    .Move
  160.  
  161. .FireOn    cmp.w    #FIRESPEED,d7
  162.     ble.s    .Move
  163.     moveq    #$00,d7
  164.     cmp.w    #10,BOB_Frame(a1)
  165.     bge.s    .On
  166.     move.w    #9,BOB_Frame(a1)
  167.  
  168. .On    addq.w    #1,BOB_Frame(a1)
  169.     cmp.w    #13,BOB_Frame(a1)
  170.     blt.s    .Move
  171.     clr.w    BOB_Frame(a1)
  172.     clr.b    FireState
  173.     move.l    SND_Rambo(pc),a0
  174.     CALL    Activate
  175.  
  176. .Move    move.l    JoyData(pc),a0
  177.     CALL    Query
  178.     move.l    JoyData(pc),a0
  179.     move.l    BOB_Rambo(pc),a1
  180.     move.w    JD_XChange(a0),d0
  181.     add.w    d0,BOB_XCoord(a1)
  182.     move.w    JD_YChange(a0),d0
  183.     add.w    d0,BOB_YCoord(a1)
  184.     move.l    JD_Buttons(a0),d0
  185.     btst    #JB_LMB,d0
  186.     beq.s    .chkRMB
  187.     st    FireState    ;Set fire to on.
  188. .chkRMB    btst    #JB_RMB,d0
  189.     beq    .Loop
  190.     rts
  191.  
  192. FireState:
  193.     dc.b    0
  194.     even
  195.  
  196. ;===========================================================================;
  197. ;                                  DATA
  198. ;===========================================================================;
  199.  
  200. JoyData:    dc.l  0
  201. Screen:        dc.l  0
  202. PIC_Background:    dc.l  0
  203. BackgroundFile:    FILENAME "GMS:demos/data/PIC.Green"
  204.  
  205. ;---------------------------------------------------------------------------;
  206.  
  207. RestoreTags:    dc.l  TAGS_RESTORE
  208. Restore:    dc.l  0
  209.         dc.l  RSA_Entries,1
  210.         dc.l  TAGEND
  211.  
  212. ;---------------------------------------------------------------------------;
  213.  
  214. BBT_Rambo:    dc.l  TAGS_BOB
  215. BOB_Rambo:    dc.l  0
  216.         dc.l  BBA_GfxCoords,.frames
  217.         dc.l  BBA_Width,32
  218.         dc.l  BBA_Height,24
  219.         dc.l  BBA_XCoord,150
  220.         dc.l  BBA_YCoord,150
  221.         dc.l  BBA_ClipLX,32
  222.         dc.l  BBA_ClipRX,320-32
  223.         dc.l  BBA_ClipTY,32
  224.         dc.l  BBA_ClipBY,256-32
  225.         dc.l  BBA_Attrib,BBF_RESTORE|BBF_CLIP|BBF_GENMASKS
  226.         dc.l    BBA_SourceTags,ID_PICTURE
  227.         dc.l    PCA_Source,.file
  228.         dc.l      PCA_BitmapTags,0
  229.         dc.l      BMA_MemType,MEM_BLIT
  230.         dc.l      TAGEND,0
  231.         dc.l    TAGEND,0
  232.         dc.l  TAGEND
  233.  
  234. .frames        dc.w    0,00   ;0 GraphicX / GraphicY
  235.         dc.w   32,00   ;1 ...
  236.         dc.w   64,00   ;2
  237.         dc.w   96,00   ;3
  238.         dc.w  128,00   ;4
  239.         dc.w  160,00   ;5
  240.         dc.w  192,00   ;6
  241.         dc.w  224,00   ;7
  242.         dc.w  256,00   ;8
  243.         dc.w  288,00   ;9
  244.         dc.w    0,48   ;10
  245.         dc.w   32,48   ;11
  246.         dc.w   64,48   ;12
  247.         dc.l  -1
  248.  
  249. .file        FILENAME "GMS:demos/data/PIC.Rambo"
  250.  
  251. ;---------------------------------------------------------------------------;
  252.  
  253. SMT_Rambo:    dc.l  TAGS_SOUND
  254. SND_Rambo:    dc.l  0
  255.         dc.l  SA_Octave,OCT_C2S
  256.         dc.l  SA_Volume,100
  257.         dc.l  SA_Source,.file
  258.         dc.l  SA_Attrib,SDF_STOPLAST
  259.         dc.l  TAGEND
  260.  
  261. .file        FILENAME "GMS:demos/data/SND.Rambo"
  262.  
  263. ;===========================================================================;
  264.  
  265. ProgName:    dc.b  "Resource Tracking Demo",0
  266. ProgAuthor:    dc.b  "Paul Manias",0
  267. ProgDate:    dc.b  "February 1998",0
  268. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1998.  Freely distributable.",0
  269. ProgShort:    dc.b  "Bob demo.",0
  270.         even
  271.  
  272.